//
//  UIColor+Extensions.swift
//  myhub
//
//  Created by x on 2024/5/14.
//

import Foundation

extension UIColor: DesignWarapper {}

public extension Wrapper where Base: UIColor {
    static func primary() -> UIColor {
        return themeService.type.associatedObject.primary
    }

    static func primaryDark() -> UIColor {
        return themeService.type.associatedObject.primaryDark
    }

    static func secondary() -> UIColor {
        return themeService.type.associatedObject.secondary
    }

    static func secondaryDark() -> UIColor {
        return themeService.type.associatedObject.secondaryDark
    }

    static func separator() -> UIColor {
        return themeService.type.associatedObject.separator
    }

    static func text() -> UIColor {
        return themeService.type.associatedObject.text
    }
}

public extension Wrapper where Base: UIColor {
    var brightnessAdjustedColor: UIColor {
        ///返回与颜色相关联的颜色组件(包括alpha)的值。与指定颜色相关联的颜色组件(包括alpha)的强度值数组。数组的大小等于颜色的numberOfComponents值。
        var components = base.cgColor.components;
        let alpha = components?.last
        components?.removeLast()
        let color = CGFloat(1-(components?.max())! >= 0.5 ? 1.0 : 0.0)
        return UIColor(red: color, green: color, blue: color, alpha: alpha!);
    }
}
